//
//  ZYCTeaLeaveRequiredCell.m
//  ZDSC
//
//  Created by 张威 on 2021/10/20.
//

#import "ZYCTeaLeaveRequiredCell.h"
@interface ZYCTeaLeaveRequiredCell ()<UITextFieldDelegate>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UIImageView *arrowImageView;
@end
@implementation ZYCTeaLeaveRequiredCell

- (void)setTitleString:(NSString *)titleString{
    _titleString = titleString;
    if ([titleString containsString:@"*"]) {
        _titleLabel.attributedText = [self returnStringWithString:titleString];
    }else{
        _titleLabel.text = titleString;
    }
}

- (void)setPlaceHolderString:(NSString *)placeHolderString{
    _placeHolderString = placeHolderString;
    _textField.placeholder = placeHolderString;
    _textField.textColor = HEX_RGB(@"#999999");
}

- (void)setContentString:(NSString *)contentString{
    _contentString = contentString;
    if (contentString.length != 0) {
        _textField.text = contentString;
        _textField.textColor = HEX_RGB(@"#333333");
    }else{
        _textField.textColor = HEX_RGB(@"#999999");
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.textField];
        [self.contentView addSubview:self.arrowImageView];
    
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.centerY.equalTo(self.contentView);
        }];
        
        [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrowImageView.mas_left).offset(-20);
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(self.titleLabel.mas_right);
        }];
        
        [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-15.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(9, 16));
        }];
        
    }
    return self;
}



- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jt"]];
    }
    return _arrowImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Medium", 16.0f) titleColor:HEX_RGB(@"#333333") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}


- (UITextField *)textField{
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.delegate = self;
        _textField.enabled = NO;
        _textField.textAlignment = NSTextAlignmentRight;
        _textField.font = kCustomFont(@"PingFangSC-Regular", 16.0f);
        _textField.textColor = HEX_RGB(@"#999999");
    }
    return _textField;
}

- (NSMutableAttributedString *)returnStringWithString:(NSString *)string{
    NSMutableAttributedString * attriString = [[NSMutableAttributedString alloc] initWithString:string];
    [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(kTitleRedColor) range:NSMakeRange(0, 1)];
    return attriString;
}

@end
